package org.ala.shopping_test.user_center.repository.user.orderBy;

import java.util.List;
import java.util.ArrayList;
import org.ala.shopping_test.user_center.repository.user.entity.UserBuyerDO;
import org.ala.tiktools.mybatis.interfaces.AbstractOrderBy;
import org.ala.tiktools.mybatis.interfaces.IComparator;


/**
 *	OrderBy (user_buyer)
 *  品类表
 *
 *	@author 骆毅 (ala)
 *	@date 2025-03-24 15:03:46
 */
public class UserBuyerOrderBy extends AbstractOrderBy<UserBuyerDO> {

    /**
     *  主要用于分表查询时的汇总排序
     *  <p> 当分表查询跨多个分表，同时查询又带有排序，需要额外的逻辑将多个分表的查询结果汇总
     */
    public UserBuyerOrderBy comparator(IComparator<UserBuyerDO> comparator) {
        this.comparator = comparator;
        return this;
    }

    public static String Id = "id";
    public static String BuyerName = "buyer_name";
    public static String BuyerLevel = "buyer_level";
    public static String CreateTime = "create_time";
    public static String ModifyTime = "modify_time";

    protected List<Item> items;
    public List<Item> getItems() {return items;}

    public static UserBuyerOrderBy build(String field, boolean isAsc) {
        UserBuyerOrderBy ob = new UserBuyerOrderBy();
        ob.items = new ArrayList<>();
        ob.items.add(Item.build(field, isAsc));
        return ob;
    }
    public static UserBuyerOrderBy ASC(String field) { return build(field, true); }
    public static UserBuyerOrderBy DESC(String field) { return build(field, false); }

    public UserBuyerOrderBy Aas(String field) { items.add(Item.build(field, true)); return this; }
    public UserBuyerOrderBy Desc(String field) { items.add(Item.build(field, false)); return this; }

    /**
     *  根据字段名取值
     */
    public Object getVal(UserBuyerDO e, Item item) {
        if (item.getColumn().equals(Id)) {return e.getId();}
        if (item.getColumn().equals(BuyerName)) {return e.getBuyerName();}
        if (item.getColumn().equals(BuyerLevel)) {return e.getBuyerLevel();}
        if (item.getColumn().equals(CreateTime)) {return e.getCreateTime();}
        if (item.getColumn().equals(ModifyTime)) {return e.getModifyTime();}
        return null;
    }
}